package com.web.rss.gui;

import java.util.HashMap;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

public class MainMenuBar extends JMenuBar {

	/*
	 * Menu structure : 
	 * Flux
	 *    Ajout
	 *    Gestion
	 * Options
	 *    Préférences
	 * Aide
	 *    À propos
	 *    Aide
	 */
	/**
	 * 
	 */
	private static final long serialVersionUID = -1396309757315998941L;

	/**
	 * Labels
	 * in tables to permit internationalisation
	 */
	private HashMap<String, HashMap<String, String>> menuItems = initLabels();
	public JMenu fluxMenu;
	public JMenuItem fluxAddItem;
	public JMenuItem fluxManageItem;
	public JMenu optionsMenu;
	public JMenuItem optionsPrefsItem;
	public JMenu helpMenu;
	public JMenuItem helpAboutItem;
	public JMenuItem helpHelpItem;
	
	public MainMenuBar (String langcode) {

		fluxMenu = new JMenu(this.menuItems.get("flux").get(langcode));
		fluxAddItem = new JMenuItem(this.menuItems.get("add").get(langcode));
		fluxManageItem = new JMenuItem(this.menuItems.get("manage").get(langcode));
		fluxMenu.add(fluxAddItem);
		fluxMenu.add(fluxManageItem);
		
		optionsMenu = new JMenu(this.menuItems.get("options").get(langcode));
		optionsPrefsItem = new JMenuItem(this.menuItems.get("prefs").get(langcode));
		optionsMenu.add(optionsPrefsItem);
		helpMenu = new JMenu(this.menuItems.get("help").get(langcode));
		helpAboutItem = new JMenuItem(this.menuItems.get("about").get(langcode));
		helpMenu.add(helpAboutItem);
		helpHelpItem = new JMenuItem(this.menuItems.get("itemHelp").get(langcode));
		helpMenu.add(helpHelpItem);
		this.add(fluxMenu);
		this.add(optionsMenu);
		this.add(helpMenu);
	}
	
	/**
	 * Initialise les chaînes pour les menus, sous forme d'une HashMap<String, HashMap<String, String>>.<br />
	 * À terme, utilisation prévue d'une table dans la base de données, ou d'un fichier de configuration externe...<br />
	 * Structure de la variable renvoyée :
	 * <ul>
	 * 	<li>{@link javax.swing.JMenu JMenu} ou {@link javax.swing.JMenuItem JMenuItem} Label 
	 * 		<ul>
	 * 			<li>"fr" => term</li>
	 * 			<li>"en" => term</li>
	 * 		</ul>
	 * 	</li>
	 * </ul>
	 * 
	 * @return 
	 */
	@SuppressWarnings("serial")
	private HashMap<String, HashMap<String, String>> initLabels() {
		HashMap<String, HashMap<String, String>> labels = new HashMap<String, HashMap<String, String>>();

		/*
		 * modèle : 
		 * labels.put(key, new HashMap(){{put(key,value); put(key,value);}});
		 */

		labels.put("flux", new HashMap<String, String>(){{put("fr", "Flux"); put("en","Feed");}});
		labels.put("add", new HashMap<String, String>(){{put("fr","Ajouter un flux"); put("en","Add feed");}});
		labels.put("manage", new HashMap<String, String>(){{put("fr","Gérer les flux"); put("en","Manage feeds");}});
		labels.put("options", new HashMap<String, String>(){{put("fr","Options"); put("en","Options");}});
		labels.put("prefs", new HashMap<String, String>(){{put("fr","Préférences"); put("en","Preferences");}});
		labels.put("help", new HashMap<String, String>(){{put("fr","Aide"); put("en","Help");}});
		labels.put("about", new HashMap<String, String>(){{put("fr","À propos"); put("en","About");}});
		labels.put("itemHelp", new HashMap<String, String>(){{put("fr","Aide"); put("en","Help");}});
		return labels;
	}
	
}
